package basicservicelogic

import (
	"context"
	"property_service/dao/model"

	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type StatusAuthorizationEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStatusAuthorizationEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusAuthorizationEditLogic {
	return &StatusAuthorizationEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// StatusAuthorizationEdit 更新状态审核授权表项
func (l *StatusAuthorizationEditLogic) StatusAuthorizationEdit(in *property_service.StatusAuthorization) (*property_service.Response, error) {
	// 获取状态审核授权表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).StatusAuthorization
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、CreatedAt、UpdatedAt
	if _, err := do.UpdateColumns(&model.StatusAuthorization{
		StatusCode:          in.StatusCode,          // 状态代码
		StatusName:          in.StatusName,          // 状态名称
		StatusDispositionID: in.StatusDispositionID, // 状态id
		UserName:            in.UserName,            // 用户名
		NickName:            in.NickName,            // 昵称
		UserID:              in.UserID,              // 用户id
		StatusGroup:         in.StatusGroup,         // 状态分组
		StatusGroupName:     in.StatusGroupName,     // 状态分组名称
		Status:              in.Status,              // 状态
		Description:         in.Description,         // 说明
		UpdatedAtuser:       in.UpdatedAtuser,       // 更新人
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
